package com.stone.front.user.dao;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stone.back.user.entity.BfCountry;
import com.stone.back.user.entity.BfUser;
import com.stone.base.dao.BaseDao;

/**
 * 用户管理Dao
 * @author Stone P
 *
 */
@Repository
public class UserFrontDao extends BaseDao implements IUserFrontDao {
	/**
	 * 查询登陆信息
	 * @param email			email
	 * @param password		密码
	 * @return				
	 */
	@Override
	public List<BfUser> userLogin(String email, String password) {
		String hql = "from BfUser where email = ? and password = ? and (type = 1 or type = 2)";
		List<BfUser> list = this.hibernateTemplate.find(hql, email, password);
		return list;
	}

	/**
	 * 通过email查找用户信息
	 * @param email		email
	 * @return
	 */
	@Override
	public List<BfUser> selectUserByEmail(String email) {
		String hql = "from BfUser where email = '" + email + "'";
		List<BfUser> list = this.hibernateTemplate.find(hql);
		return list;
	}

	/**
	 * 通过验证码查找用户信息
	 * @param checkCode		验证码
	 * @return
	 */
	@Override
	public List<BfUser> selectUserByCheckCode(String checkCode) {
		String hql = "from BfUser where status = 0 and checkcode = '" + checkCode + "'";
		List<BfUser> list = this.hibernateTemplate.find(hql);
		return list;
	}
	
	/**
	 * 查询国家列表
	 * @return
	 */
	@Override
    public @ResponseBody List<BfCountry> selectCountry() {
		String hql = "from BfCountry";
		List<BfCountry> list = this.hibernateTemplate.find(hql);
		return list;
	}

	/**
	 * 增加用户
	 * @param user	用户信息
	 * @return
	 */
	@Override
	public Integer addUser(BfUser user) {
		return (Integer) this.hibernateTemplate.save(user);
	}

	/**
	 * 修改用户
	 * @param user	用户信息
	 * @return
	 */
	@Override
	public void updateUser(BfUser user) {
		this.hibernateTemplate.update(user);
	}

	/**
	 * 查询用户详情
	 * @param userId	用户Id
	 * @return
	 */
	@Override
	public BfUser selectUserDetail(int userId) {
		return this.hibernateTemplate.get(BfUser.class, userId);
	}
}
